package com.maycari.captainbi;
import java.math.BigDecimal;

import com.alibaba.excel.EasyExcel;
import com.maycari.captainbi.data.dto.Captain1Dto;

import java.io.File;
import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 王宏伟
 * @DateTime: 2021/4/2 14:16
 * @Description: TODO
 */
public class createset {


    public static void main(String[] args) throws IllegalAccessException {
        Captain1Dto po = new Captain1Dto();
        po.setId(0L);
        po.setParentId(0);
        po.setAsin("");
        po.setParentAsin("");
        po.setIsParent(0);
        po.setCountryId(0);
        po.setTransportMode(0);
        po.setTaxCode("");
        po.setHandingTime(0);
        po.setStartSellingDate(0);
        po.setRestockDate(0);
        po.setIsGiftWrapAvailable(0);
        po.setIsGiftMessageAvailable(0);
        po.setCategoryId(0);
        po.setBrandSettledDown(0);
        po.setMultivariant(0);
        po.setSaleForm(0);
        po.setBrandSettledType(0);
        po.setLocalCategoryId(0);
        po.setSourceUrl("");
        po.setParentSku("");
        po.setTitle("");
        po.setProductId("");
        po.setBrand("");
        po.setDesignerid("");
        po.setConditiontypeselctid("");
        po.setConditionvalueid("");
        po.setDescription("");
        po.setBulletPoint("");
        po.setSearchTerms("");
        po.setPlatinumKeywords("");
        po.setSku("");
        po.setUpc("");
        po.setImage("");
        po.setCondition("");
        po.setConditionDesc("");
        po.setPrice(new BigDecimal("0"));
        po.setShipPrice(new BigDecimal("0"));
        po.setCurrencyCode("");
        po.setSalePrice(new BigDecimal("0"));
        po.setSaleStartTime(0);
        po.setSaleEndTime(0);
        po.setNumber(0);
        po.setCreateTime(0);
        po.setModifiedTime(0);
        po.setGroup(0);
        po.setStatus(0);
        po.setError("");
        po.setUpStatus(0);
        po.setSaleNums(0);
        po.setProductIdType("");

       // System.out.println(objectToMap(dto));
    }


    /**
     * 获取利用反射获取类里面的值和名称
     *
     * @param obj
     * @return
     * @throws IllegalAccessException
     */
    public static String objectToMap(Object obj) throws IllegalAccessException {
        Class<?> clazz = obj.getClass();
        System.out.println(clazz);
        File file = new File("C:\\Users\\Administrator\\Desktop\\excel.xlsx");
        List<Map<String, String>> objects = EasyExcel.read(file).headRowNumber(0).doReadAllSync();

        StringBuilder sb = new StringBuilder();
        String className = obj.getClass().getName().substring(obj.getClass().getName().lastIndexOf(".") + 1);
        sb.append(className).append(" dto = new ").append(className).append("();\n");
        int i = 0;
        for (Field field : clazz.getDeclaredFields()) {
            field.setAccessible(true);
            String fieldName = field.getName();
            if (fieldName.equals("serialVersionUID")) {
                continue;
            }
            String methodName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
            sb.append("dto.").append(methodName).append("(v.");
            String typeName = field.getType().getName();
            if (typeName.contains("String")) {
                sb.append("getString");
            } else if (typeName.contains("Long")) {
                sb.append("getLong");
            } else if (typeName.contains("Long")) {
                sb.append("getLong");
            } else if (typeName.contains("Integer")) {
                sb.append("getInteger");
            } else if (typeName.contains("BigDecimal")) {
                sb.append("getBigDecimal");
            }
            sb.append("(\"").append(objects.get(i).get(0)).append("\"));").append("\n");
            i++;
        }
        return sb.toString();
    }


}
